package com.zjgeport.zjgdanger;


import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.soar.controller.SlideLayout;

public class CommonActivity extends AppCompatActivity {

    private Button back,category;
    public static SlideLayout slideLayout; // 滑动Layout

    protected String[] mMonths = new String[] {
            "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
    };

    protected String[] mParties = new String[] {
            "Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
            "Party I", "Party J", "Party K", "Party L", "Party M", "Party N", "Party O", "Party P",
            "Party Q", "Party R", "Party S", "Party T", "Party U", "Party V", "Party W", "Party X",
            "Party Y", "Party Z"
    };

    protected Typeface mTfRegular;
    protected Typeface mTfLight;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTfRegular = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
        mTfLight = Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf");
    }

    protected float getRandom(float range, float startsfrom) {
        return (float) (Math.random() * range) + startsfrom;
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.move_left_in_activity, R.anim.move_right_out_activity);
    }

    /**
     * 初始化公共的事件
     */
    public void initCommonListener()
    {
        initBack();
    }

    private void initBack(){
         //主页按钮初始化
        back = (Button) CommonActivity.this.findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                finish();
            }
        });
    }

    /**
     * 初始化公共的事件,包含返回与滑动
     */
    public void initSlideListener()
    {
        // 主页按钮初始化
//        back = (Button) CommonActivity.this.findViewById(R.id.back);
//        slideLayout = (SlideLayout) findViewById(R.id.slidelayout);
//        back.setOnClickListener(new View.OnClickListener()
//        {
//            public void onClick(View v)
//            {
//                finish();
//            }
//        });
//
//        category = (Button) findViewById(R.id.category);
//
//        category.setOnClickListener(new View.OnClickListener()
//        {
//            public void onClick(View v)
//            {
//                slideLayout.snapToScreen(1, false);
//            }
//        });
    }

    /**
     * 获取当前Activity上的TextView
     *
     * @param id
     *            TextView的资源Id
     * @return TextView
     */
    public TextView findTextViewById(int id)
    {
        return (TextView) this.findViewById(id);
    }

    /**
     * 获取当前Activity上的TextView的字符值
     *
     * @param id
     *            id TextView的资源Id
     * @return String
     */
    public String findTextViewStringById(int id)
    {
        return String.valueOf(this.findTextViewById(id).getText());
    }

    /**
     * 获取当前Activity上的EditText
     *
     * @param id
     *            EditText的资源Id
     * @return EditText
     */
    public EditText findEditTextById(int id)
    {
        return (EditText) this.findViewById(id);
    }


    /**
     * 获取当前Activity上的EditText的字符值
     *
     * @param id
     *            id EditText的资源Id
     * @return String
     */
    public String findEditTextStringById(int id)
    {
        return String.valueOf(this.findEditTextById(id).getText());
    }

    /**
     * 获取当前Activity上的Button
     *
     * @param id
     *            Button的资源Id
     * @return Button
     */
    public Button findButtonById(int id)
    {
        return (Button) this.findViewById(id);
    }

    /**
     * 获取当前Activity上的ImageButton
     *
     * @param id
     *            ImageButton的资源Id
     * @return ImageButton
     */
    public ImageButton findImageButtonById(int id)
    {
        return (ImageButton) this.findViewById(id);
    }

    public GridView findGridViewById(int id){
        return (GridView) this.findViewById(id);
    }
    public ListView findListViewById(int id){
        return (ListView) this.findViewById(id);
    }

    /**
     * toast消息提示(默认短时间)
     *
     * @param 当前Activity
     * @param message
     */
    public void showToast(String message)
    {
        this.showToast(message, Toast.LENGTH_SHORT);
    }

    /**
     * toast消息提示(可定制显示时间长度）
     *
     * @param 当前Activity
     * @param 消息
     * @param 显示时间的长度
     */
    public void showToast(String message, int toast)
    {
        Toast.makeText(this.getApplication(), message, toast).show();
    }
}
